//const Store = require("electron-store");
/**
 * 全局参数
 */
import Store from "electron-store";
import { uuid } from "../utils/uuid";

const store = new Store();

const key = "ginfo";

const defaultGlobal = {
  packageName: "com.jooki",
  author: "lihui580@gmail.com",
  version: "1.0v",
  prefix: "tb_",
  suffix: "",
  copyright:
    "/**\n * Copyright 2020 简创网 https://www.jianchuang.com\n * <p>\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * <p>\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n * <p>\n * You should have received a copy of the GNU General Public License\n * along with this program.  If not, see http://www.gnu.org/licenses\n */",
};

function set(global) {
  let ggg = {};
  Object.keys(defaultGlobal).forEach((key) => {
    ggg[key] = global[key];
  });
  //console.log(ggg);
  ggg.id = uuid();
  store.set(key, ggg);
  return;
}

function get() {
  var global = store.get(key);
  //console.log(global);
  if (global == null) {
    set(defaultGlobal);
    global = defaultGlobal;
  }

  return global;
}

function reset() {
  store.set(key, defaultGlobal);
}

let GlobalStore = {
  set,
  get,
  reset,
};

export default GlobalStore;
